1025C - Plasticine zebra - CodeForces Solution


constructive algorithms implementation *1600

Please click on ads to support us..

Python Code:

s = input()
n = len(s)
s += s 

ans, idx = 0, 0 
while idx < n:
    st = idx 
    idx += 1
    while idx < st + n and s[idx] != s[idx - 1]:
        idx += 1 
    ans = max(ans, idx - st)
print(ans)

C++ Code:

/* Quick Note :
 * Jangan Mikir Lama - lama, sampahin dulu aja kalo OI
 * Always Try to reset
*/
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ld PI = 4*atan((ld)1);
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll nax = 0;

string s;

int main(){ 
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    //freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    
    cin >> s;
    ll cnt = 1;
    ll ans = 1;
    for(ll i = 1; i < 2 * s.size(); i++){
		char idx = '0';
		if(i >= s.size()){
			idx = s[i-s.size()];
		}
		else idx = s[i];
		
		char bfr = '0';
		if(i - 1 >= s.size()){
			bfr = s[i-s.size()-1];
		}
		else bfr = s[i-1];
		
		if(idx == bfr){
			ans = max(ans, cnt);
			cnt = 1;
		}
		else cnt++;
	}
	ans = max(ans, cnt);
	ans = min(ans, (ll)s.size());
	cout << ans << '\n';
    
}


Comments

Submit
0 Comments
More Questions

876A - Trip For Meal
1326B - Maximums
1635C - Differential Sorting
961A - Tetris
1635B - Avoid Local Maximums
20A - BerOS file system
1637A - Sorting Parts
509A - Maximum in Table
1647C - Madoka and Childish Pranks
689B - Mike and Shortcuts
379B - New Year Present
1498A - GCD Sum
1277C - As Simple as One and Two
1301A - Three Strings
460A - Vasya and Socks
1624C - Division by Two and Permutation
1288A - Deadline
1617A - Forbidden Subsequence
914A - Perfect Squares
873D - Merge Sort
1251A - Broken Keyboard
463B - Caisa and Pylons
584A - Olesya and Rodion
799A - Carrot Cakes
1569B - Chess Tournament
1047B - Cover Points
1381B - Unmerge
1256A - Payment Without Change
908B - New Year and Buggy Bot
979A - Pizza Pizza Pizza